#include "Image.h"

Image::Image()
    : image_name("") {}

Image::~Image() {
}

void Image::editImage(const QString& imagepath) {
    std::string temp = imagepath.toStdString();

    easypr::CPlateRecognize pr;
    pr.setResultShow(false);
    pr.setDebug(false);
    pr.setDetectType(easypr::PR_DETECT_CMSER);

    std::vector<easypr::CPlate> plateVec;
    cv::Mat src = cv::imread(temp);

    int result = pr.plateRecognize(src, plateVec);
    if (result == 0 && !plateVec.empty()) {
        // 识别成功
        auto plate = plateVec.at(0);
        image_name = plate.getPlateStr();

        cv::Mat plateMat = plate.getPlateMat();
        cv::Mat temp;
        cv::cvtColor(plateMat, temp, COLOR_BGR2RGB);
        image = QImage(temp.data, temp.cols, temp.rows, QImage::Format_RGB888);
    } else {
        // 识别失败
        qDebug() << "Image recognize fatal";
    }
}

std::string Image::getImageName() {
    return image_name;
}

QImage Image::getImage() {
    return image.copy();
}
